#!/bin/sh
export OSSSERVER=./oss-server-1.1.jar

export OSSSERVER_port=18000

case "$1" in

start)
        ## 启动 OSSSERVER
        echo "--------OSSSERVER开始启动--------------"
        nohup java -jar $OSSSERVER>/dev/null 2>&1 &
        OSSSERVER_pid=`lsof -i:$OSSSERVER_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$OSSSERVER_pid" ]
            do
              OSSSERVER_pid=`lsof -i:$OSSSERVER_port|grep "LISTEN"|awk '{print $2}'`
            done
        echo "APP pid is $OSSSERVER_pid"

        echo "--------OSSSERVER启动成功--------------"
        ;;

 stop)
        P_ID=`ps -ef | grep -w $OSSSERVER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===APP process not exists or stop success"
        else
            kill -9 $P_ID
            echo "APP killed success"
        fi


        echo "===stop success==="
        ;;

restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restart success==="
        ;;
esac
exit 0
